layui.use(['form','layer','jquery'],function(){
	var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		$ = layui.jquery;
    //校验登录状态
    if(isNotLogIn()){
        return;
    }

    //添加验证规则
    form.verify({
        username:function (value,item) {
            if(value.length < 6||value.length > 14){
                return "用户名长度需在6-14位之间";
            }
        },
        pwd : function(value, item){
            if(value.length < 6||value.length > 14){
                return "密码长度长度需在6-14位之间";
            }
        },
        confirmPwd : function(value, item){
            if(!new RegExp($("#pwd").val()).test(value)){
                return "两次输入密码不一致，请重新输入！";
            }
        }
    });

 	form.on("submit(addManager)",function(data){
        //校验登录状态
        if(isNotLogIn()){
            return false;
        }
 		var optManagerId = getCookie("managerId");
        //提交修改
        var index = layer.load(3);
        $.ajax({
            url:"/CivilAffairs/manager/addManager",
            type:"post",
            data:{"managerInfo":JSON.stringify(data.field),"optManagerId":optManagerId},
            dataType:"json",
            success:function(result){
                layer.close(index);
                if(checkResult(result)){
                    top.layer.close(index);
                    layer.msg(result.detail,{icon:6});
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }
            },
            error : function(result) {
                layer.close(index);
                console.log("获取、修改服务信息出错:"+result.status+","+result.statusMessage+",beneficiaryId:"+beneficiaryId);
                layer.msg("系统异常,请稍后重试",{icon:2});
            }
        });
 		return false;
 	});
	
});

